package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.InvoiceListItem;

import java.util.List;

/**
 * Created by yang on 15/11/24.
 */
public class InvoiceListAdapter extends BaseAdapter {
    private Context mContext;
    private List<InvoiceListItem> data;
    private View.OnClickListener listener;
    public InvoiceListAdapter(Context context, List<InvoiceListItem> data,View.OnClickListener listener){
        mContext = context;
        this.data = data;
        this.listener = listener;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_layout_invoice_list_view,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();

        InvoiceListItem invoiceListItem = data.get(position);
        holder.tv_company.setText(invoiceListItem.getInv_company());
        holder.tv_nashui.setText(invoiceListItem.getInv_code());
        holder.tv_regAddress.setText(invoiceListItem.getInv_reg_addr());
        holder.tv_regPhone.setText(invoiceListItem.getInv_reg_phone());
        holder.tv_bank.setText(invoiceListItem.getInv_reg_bname());
        holder.tv_bankAccount.setText(invoiceListItem.getInv_reg_baccount());
        holder.tv_name.setText(invoiceListItem.getInv_rec_name());
        holder.tv_mobile.setText(invoiceListItem.getInv_rec_mobphone());
        holder.tv_sheng.setText(invoiceListItem.getInv_rec_province());
        holder.tv_gotoAddress.setText(invoiceListItem.getInv_goto_addr());
        holder.img_delete.setTag(position);
        holder.img_delete.setOnClickListener(listener);
        return convertView;
    }

    public void setData(List<InvoiceListItem> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    class ViewHolder{
        TextView tv_company;
        TextView tv_nashui;
        TextView tv_regAddress;
        TextView tv_regPhone;
        TextView tv_bank;
        TextView tv_bankAccount;
        TextView tv_name;
        TextView tv_mobile;
        TextView tv_sheng;
        TextView tv_gotoAddress;
        ImageView img_delete;

        public ViewHolder(View view){
            tv_company = (TextView) view.findViewById(R.id.invoice_01);
            tv_nashui = (TextView) view.findViewById(R.id.invoice_02);
            tv_regAddress = (TextView) view.findViewById(R.id.invoice_03);
            tv_regPhone = (TextView) view.findViewById(R.id.invoice_04);
            tv_bank = (TextView) view.findViewById(R.id.invoice_05);
            tv_bankAccount = (TextView) view.findViewById(R.id.invoice_06);
            tv_name = (TextView) view.findViewById(R.id.invoice_07);
            tv_mobile = (TextView) view.findViewById(R.id.invoice_08);
            tv_sheng = (TextView) view.findViewById(R.id.invoice_09);
            tv_gotoAddress = (TextView) view.findViewById(R.id.invoice_10);
            img_delete = (ImageView) view.findViewById(R.id.item_delete);
        }
    }
}
